﻿using System;
using OneMG.Phoenix.Entity;
using OneMG.Phoenix.Respository;
using IBatisNet.DataMapper;
using OneMG.Phoenix.Kernel.IBatisUtil;
using System.Collections.Generic;
using System.Collections;

namespace OneMG.Phoenix.IBatisRepository
{
    public class ProductRepository : BaseIBatisDao,IProduct
    {
        public ProductRepository()
            : base("yihaoke_newMap.Config")
        {

        }
        public System.Int32 AddProduct(EProduct entity)
        {
			string stmtId = "ProductMap.InsertProduct";
			 Object obj = base.SqlMapper.Insert(stmtId, entity);
			 return (System.Int32)obj;
        }
        
		public  EProduct GetByProductID (System.Int32 productID)
        {
			string stmtId = "ProductMap.SelectByProductID";
			return base.SqlMapper.QueryForObject<EProduct>(stmtId, productID);
        }
        
        public  void DeleteByProductID (System.Int32 productID)
        {
			string stmtId = "ProductMap.DeleteByProductID";
			base.SqlMapper.Update(stmtId, productID);
        }
        
        public  void UpdateByProductID (EProduct entity)
        {
			string stmtId = "ProductMap.UpdateByProductID";
			base.SqlMapper.Update(stmtId, entity);
        }

        public IList<EProduct> GetPagedList(int pageSize, int pageIndex,int categoryID, out int totalRecord)
        {
            Hashtable ht = new Hashtable();
            ht.Add("CateID", categoryID);


            totalRecord = base.SqlMapper.QueryForObject<int>("ProductMap.SelectAllRecord", ht);

            if (pageIndex > totalRecord)
                pageIndex = 1;

            int startPage = pageSize * pageIndex - pageSize;

            int endPage = pageSize * pageIndex;

            ht.Add("StartPage", startPage);
            ht.Add("EndPage", endPage);

            string stmtId = "ProductMap.SelectAllPagedList";

            return base.SqlMapper.QueryForList<EProduct>(stmtId, ht);


        }




    }
}

